/////////////////////////////////////////////
// ObjectARX defined commands

#include "StdAfx.h"
#include "StdArx.h"


// This is command 'WINDO'
void windo()
{
	char kw[10];
	int retCode;

	draw_window();

	while(strcmp(kw, "eXit") != 0)
	{

		acedInitGet(NULL, "Undo Draw eXit");
		retCode = acedGetKword("\nWindow - [Undo/eXit/Draw]<Draw> ", kw);

		switch(retCode)
		{
			case RTERROR :
				acutPrintf("\nError in acedGetKword ");
				actrTransactionManager->endTransaction();
				strcpy(kw, "eXit");
			break;

			case RTCAN :
				acutPrintf("\nUser canceled. ");
				actrTransactionManager->endTransaction();
				strcpy(kw, "eXit");
			break;

			case RTNONE:
				strcpy(kw, "Draw");
				retCode = RTNORM;
			break;
		}// switch

		if(strcmp(kw, "Draw") == 0)
		{
			draw_window();
		}
		else if(strcmp(kw, "Undo") == 0)
		{
			actrTransactionManager->abortTransaction();
		}

	}// while

	actrTransactionManager->endTransaction();
}

// This is command 'PWI'
void pickWindowInfo()
{
	AcDbObject *pObj;
	CMARectWindow *pRectWindow = NULL;
	AcDbObjectId entId, objId;

	ads_name ename;
	ads_point pickpt;
	int rc;

	// Select the Window entity to get its handle
	rc = acedEntSel("\nSelect Window entity ", ename, pickpt);
	if(rc != RTNORM)
	{
		acutPrintf("\nError selecting Window entity ");
		return;
	}

	// Get the entity object ID
	acdbGetObjectId(entId, ename);

	// Open the enity for a read operation
	acdbOpenObject(pObj, entId, AcDb::kForRead);

	// Is pObj a RectWindow object ?
	pRectWindow = CMARectWindow::cast(pObj);
	if(!pRectWindow)
	{
		acutPrintf("\nObject is not a RectWindow ");
		pObj->close();
		return;
	}

	acutPrintf("\nWindow Type = %s", pRectWindow->m_strWindType);
	acutPrintf("\nRows = %d", pRectWindow->getWindowRows());
	acutPrintf("\nCols = %d", pRectWindow->getWindowCols());
	acutPrintf("\nLength = %.2lf", pRectWindow->getWindowLength());
	acutPrintf("\nHeight = %.2lf", pRectWindow->getWindowHeight());
	acutPrintf("\nStart Point = (%.2lf, %.2lf)",
				pRectWindow->getWindowStartPoint().x,
				pRectWindow->getWindowStartPoint().y);

	pRectWindow->close();
}

